/**
 *   DataSlim - Lazy Loading Framework
 *   Copyright (C) 2007 Rodolfo Dias
 *   
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 
 */

package net.dataslim.test.serialize;

import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class MapUtils
{
	public static Map toHashMap(Collection collection, String campo) throws Exception
	{
		Map map = new HashMap(collection.size());
		for (Iterator it = collection.iterator(); it.hasNext();)
		{
			Object o = it.next();
			Method m = o.getClass().getMethod("get"
					+ (String.valueOf(campo.charAt(0)).toUpperCase() + campo.substring(1)),
					new Class[]{});
			Object fieldKey = m.invoke( o, new Object[]{});
			map.put(fieldKey, o);
		}
		return map;
	}
}
